/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vng.zing.survey.utility;

import com.vng.cookies.CookieUtils;
import com.vng.session.client.SessionClient;
import com.vng.session.thrift.Session;
import com.vng.session.thrift.SessionResult;
import com.vng.zing.stdprofile2.client.StdpofileClient;
import com.vng.zing.stdprofile2.thrift.TValue;
import com.vng.zing.stdprofile2.thrift.TValueResult;
import com.vng.zing.zcommon.thrift.OpHandle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author kienpd
 */
public class ZingMeService {

    public static Session getSesstion(HttpServletRequest request) {
        System.out.println("session bat dau");
        SessionClient sessionClient = SessionClient.getInstance();
        System.out.println("session bat dau 1");
        // get cookies
        String sessionId = CookieUtils.getCookie(request, "vngauth", null);
        if (sessionId == null) {
            return null;
        }
        System.out.println("sessionId:" + sessionId);
        try {
            SessionResult sessionResult = sessionClient.GetSession(sessionId);
            if(sessionResult.getResultCode() != 0){
                return  null;
                
            }
            return sessionResult.getSession();
        } catch (Exception ex) {
            Logger.getLogger(ZingMeService.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }
    public static TValue getproflieUser(String accoutName){
        OpHandle opHandle = new OpHandle();
          opHandle.setSource("chat");
         opHandle.setAuth("XOeG9v");
         StdpofileClient stdpofileClient =StdpofileClient.getInstance();
        try {
            TValueResult tValueResult = stdpofileClient.getByName(opHandle, accoutName);
            if(tValueResult.getError() !=0){
                return  null;
            }
            return tValueResult.getValue();
        } catch (Exception ex) {
            Logger.getLogger(ZingMeService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

}
